package org.apache.struts.register.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts.register.model.Person;
import org.apache.struts.register.util.HibernateUtils;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

public class register_submit extends ActionSupport {
    private static final long serialVersionUID = 1L;
    private Person personBean;

    @Override
    public String execute() {

        //得到Session对象
        Session session = HibernateUtils.openSession();

        //使用Hibernate操作数据库，都要开启事务,得到事务对象
        Transaction transaction = session.getTransaction();

        //开启事务
        transaction.begin();

        //把对象添加到数据库中
        session.save(personBean);

        //提交事务
        transaction.commit();

        //关闭Session
        session.close();
        return SUCCESS;
    }

    public Person getPersonBean() {
        return personBean;
    }

    public void setPersonBean(Person personBean) {
        this.personBean = personBean;
    }

}
